package com.freewater.cargotracker.infrastructure.config;

import com.freewater.cargotracker.application.BookingService;
import com.freewater.cargotracker.application.internal.DefaultBookingService;
import com.freewater.cargotracker.domain.model.cargo.CargoRepository;
import com.freewater.cargotracker.domain.model.handlingevent.HandlingEventFactory;
import com.freewater.cargotracker.domain.model.location.LocationRepository;
import com.freewater.cargotracker.domain.model.voyage.VoyageRepository;
import com.freewater.cargotracker.domain.service.AllocationCheckerService;
import com.freewater.cargotracker.domain.service.DefaultOverBookingPolicy;
import com.freewater.cargotracker.domain.service.OverBookingPolicy;
import com.freewater.cargotracker.infrastructure.allocation.AllocationCheckerServiceImpl;
import com.freewater.cargotracker.infrastructure.allocation.SalesManagementInterface;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class AppConfig {

    @Bean
    public HandlingEventFactory handlingEventFactory(CargoRepository cargoRepository,
                                                     LocationRepository locationRepository,
                                                     VoyageRepository voyageRepository) {
        return new HandlingEventFactory(cargoRepository,
                locationRepository,
                voyageRepository);
    }

    @Bean
    public OverBookingPolicy overBookingPolicy(VoyageRepository voyageRepository) {
        return new DefaultOverBookingPolicy(voyageRepository);
    }

    @Bean
    public AllocationCheckerService allocationCheckerService() {
        return new AllocationCheckerServiceImpl(new SalesManagementInterface());
    }

    @Bean
    public BookingService bookingService(OverBookingPolicy overBookingPolicy,
                                         CargoRepository cargoRepository,
                                         LocationRepository locationRepository,
                                         AllocationCheckerService allocationCheckerService) {
        return new DefaultBookingService(overBookingPolicy,
                cargoRepository,
                locationRepository,
                allocationCheckerService);
    }
}
